//
//  HPFestivalDetailViewController.m
//  HappyPenguin
//
//  Created by zhuangyihang on 1/12/16.
//  Copyright © 2016 zhuangyihang. All rights reserved.
//

#import "HPFestivalDetailViewController.h"
#import "KSViewPagerView.h"
#import "HPFestivalDetailDataSource.h"

@interface HPFestivalDetailViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) KSViewPagerView *pagerView;
@property (nonatomic, strong) NSMutableArray *dataSources;

@end

@implementation HPFestivalDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setBaseNavigationBarTitle:self.title];
    [self addBackButton:nil];
    
    [self setupUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)setupUI{
    NSArray *a = @[@"今天生日",@"临近生日",@"本月生日"];
    self.pagerView = [[KSViewPagerView alloc]initWithArray:a];
    [self.baseContentView addSubview:self.pagerView];
    [self.pagerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.centerX.top.equalTo(self.baseContentView);
        make.height.equalTo(@40);
        
    }];
    [self.pagerView setActiveColor:[UIConstants getAppColor]];
    [self.pagerView setInactiveColor:[UIColor colorWithRGB:0xbbbbbb]];
    self.pagerView.backgroundColor = [UIColor whiteColor];
    [self.pagerView setTitleFont:[UIConstants getFont:15]];
    [self.pagerView setCursorPosition:0];
    self.pagerView.click = ^(KSViewPagerView *v, NSNumber *index){
        
    };
    
    
    UIScrollView *scrollView = [UIScrollView new];
    [self.baseContentView addSubview:scrollView];
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pagerView.mas_bottom);
        make.bottom.equalTo(self.baseContentView);
        make.width.centerX.equalTo(self.baseContentView);
    }];
    
    self.dataSources = [NSMutableArray array];
    for (int i = 0; i < a.count; i++) {
        UITableView *tableView = [UITableView new];
        [scrollView addSubview:tableView];
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.centerY.equalTo(scrollView);
            make.left.equalTo(scrollView).offset(i * [UIScreen mainScreen].bounds.size.width);
        }];
        tableView.tableFooterView = [UIView new];
        
        HPFestivalDetailDataSource *dataSource = [[HPFestivalDetailDataSource alloc] initWithTableView:tableView];
        [self.dataSources addObject:dataSource];
    }
    scrollView.contentSize = CGSizeMake(a.count*[UIScreen mainScreen].bounds.size.width, 0);
    scrollView.pagingEnabled = YES;
    scrollView.delegate = self;
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    float page = scrollView.contentOffset.x/scrollView.width;
    [self.pagerView setCursorPosition:page];
}

@end
